﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Xeralabs.Core;
using System.Threading;
using Xeralabs.GDESK.UnitTests.Objects;

namespace Xeralabs.GDESK.UnitTests
{
    [TestClass]
    public class InitializationTests
    {
        [TestMethod]
        public void SimpleInit()
        {
            if (XGDESK.Initialize(XGDESK.InitParams.Default))
                XGDESK.End();
        }

        [TestMethod]
        public void InitAndStart()
        {
            if (XGDESK.Initialize(XGDESK.InitParams.Default))
            {
                XGDESK.Start();
                XGDESK.End();
            }
        }

        [TestMethod]
        public void FullInit()
        {
            if (XGDESK.Initialize(new XGDESK.InitParams
            {
                Forced = false,
                KernelMessagePoolFullInit = true,
                KernelMessagePoolMaxSize = 1000,
                SimulationFrameRate = 60
            }))
                XGDESK.End();
        }

        [TestMethod]
        public void FullInitAndStart()
        {
            if (XGDESK.Initialize(new XGDESK.InitParams
            {
                Forced = false,
                KernelMessagePoolFullInit = true,
                KernelMessagePoolMaxSize = 1000,
                SimulationFrameRate = 60
            }))
            {
                XGDESK.Start();
                XGDESK.End();
            }
        }

        [TestMethod]
        public void InitAndRun()
        {
            if (XGDESK.Initialize(XGDESK.InitParams.Default))
            {
                XGDESK.Start();
                Thread.Sleep(5000);
                XGDESK.End();
            }
        }

        [TestMethod]
        public void FullInitAndRun()
        {
            if (XGDESK.Initialize(new XGDESK.InitParams
            {
                Forced = false,
                KernelMessagePoolFullInit = true,
                KernelMessagePoolMaxSize = 1000,
                SimulationFrameRate = 60
            }))
            {
                XGDESK.Start();
                Thread.Sleep(500);
                XGDESK.End();
                Thread.Sleep(1000);
            }
        }

        [TestMethod]
        public void InitDeployRun()
        {
            if (XGDESK.Initialize(XGDESK.InitParams.Default))
            {
                XGDESK.Start();
                Thread.Sleep(500);
                for (ulong a = 20; a < 25; a++)
                {
                    TestEntity entity = new TestEntity();
                    entity.SetGUID64(a);
                    XGDESK.AddEntity(entity);
                }
                XGDESK.End();
                Thread.Sleep(1000);
            }
        }

        [TestMethod]
        public void FullInitDeployRun()
        {
            if (XGDESK.Initialize(new XGDESK.InitParams
            {
                Forced = false,
                KernelMessagePoolFullInit = true,
                KernelMessagePoolMaxSize = 100000,
                SimulationFrameRate = 60
            }))
            {
                XGDESK.Start();
                Thread.Sleep(500);
                for (ulong a = 2; a <= 1000; a++)
                {
                    TestEntity entity = new TestEntity();
                    entity.SetGUID64(a);
                    XGDESK.AddEntity(entity);
                }
                XGDESK.End();
                Thread.Sleep(60000);
            }
        }
    }
}
